home *** CD-ROM | disk | FTP | other *** search
- // Addressing Modes
- enum {
- None = 0x00,
- Relative = 0x02,
- IndX = 0x01,
- ZeroPage = 0x05,
- Immediate = 0x09,
- Accumulator = 0x09,
- Absolute = 0x0D,
- IndY = 0x11,
- ZeroPageX = 0x15,
- AbsoluteY = 0x19,
- AbsoluteX = 0x1D,
- ZeroPageY = 0x20,
- Indirect = 0x2D
- };
-
- // BASE opcodes
- enum {
- ADC = 0x60,
- AND = 0x20,
- ASL = 0x01,
- /*
- BCC = 0x90,
- BCS = 0xB0,
- BEQ = 0xF0,
- BNE = 0xD0,
- BMI = 0x30,
- BPL = 0x10,
- BVC = 0x50,
- BVS = 0x70,
- */
-
- BCC = 0x8E,
- BCS = 0xAE,
- BEQ = 0xEE,
- BNE = 0xCE,
- BMI = 0x2E,
- BPL = 0x0E,
- BVC = 0x4E,
- BVS = 0x6E,
-
- BIT = 0x1F,
- BRK = 0x00,
- CLC = 0x18,
- CLD = 0xD8,
- CLI = 0x58,
- CLV = 0xB8,
- CMP = 0xC0,
- CPX = 0xD7,
- CPY = 0xB7,
- DEC = 0xC1,
- DEX = 0xCA,
- DEY = 0x88,
- EOR = 0x40,
- INC = 0xE1,
- INX = 0xE8,
- INY = 0xC8,
- JMP = 0x3F,
- JSR = 0x13,
- LDA = 0xA0,
- LDX = 0xA1, // Exception
- LDY = 0x9F, // Exception
- LSR = 0x41,
- NOP = 0xEA,
- ORA = 0x00,
- PHA = 0x48,
- PHP = 0x08,
- PLA = 0x68,
- PLP = 0x28,
- ROL = 0x21,
- ROR = 0x61,
- RTI = 0x40,
- RTS = 0x60,
- SBC = 0xE0,
- SEC = 0x38,
- SED = 0xF8,
- SEI = 0x78,
- STA = 0x80,
- STX = 0x81,
- STY = 0x79,
- TAX = 0xAA,
- TAY = 0xA8,
- TSX = 0xBA,
- TXA = 0x8A,
- TXS = 0x9A,
- TYA = 0x98
- };
-
- // Processor Bits
- enum {
- CBit = 1 << 0,
- ZBit = 1 << 1,
- IBit = 1 << 2,
- DBit = 1 << 3,
- BBit = 1 << 4,
- VBit = 1 << 6,
- NBit = 1 << 7
- };
-
- // Exceptions to the addressing mode values
- enum {
- _LDX_Immediate = 0xA2,
- _LDY_Immediate = 0xA0
- };
-
- #define ZEROBYTE_OP_FUNCTION_PROTO(op) extern void _##op(void)
- #define ONEBYTE_OP_FUNCTION_PROTO(op) extern void _##op(UInt8)
- #define TWOBYTE_OP_FUNCTION_PROTO(op) extern void _##op(UInt8*)
- #define TWOBYTE_OP_FUNCTION_PROTOPC(op) extern void _##op(UInt16)
-
- ONEBYTE_OP_FUNCTION_PROTO(ADC); // ADC
- ONEBYTE_OP_FUNCTION_PROTO(AND); // AND
- TWOBYTE_OP_FUNCTION_PROTO(ASL); // ASL
- ONEBYTE_OP_FUNCTION_PROTO(BCC); // BCC
- ONEBYTE_OP_FUNCTION_PROTO(BCS); // BCS
- ONEBYTE_OP_FUNCTION_PROTO(BEQ); // BEQ
- ONEBYTE_OP_FUNCTION_PROTO(BNE); // BNE
- ONEBYTE_OP_FUNCTION_PROTO(BMI); // BMI
- ONEBYTE_OP_FUNCTION_PROTO(BPL); // BPL
- ONEBYTE_OP_FUNCTION_PROTO(BVC); // BVC
- ONEBYTE_OP_FUNCTION_PROTO(BVS); // BVS
- TWOBYTE_OP_FUNCTION_PROTO(BIT); // BIT
- ZEROBYTE_OP_FUNCTION_PROTO(BRK); // BRK
- ZEROBYTE_OP_FUNCTION_PROTO(CLC); // CLC
- ZEROBYTE_OP_FUNCTION_PROTO(CLD); // CLD
- ZEROBYTE_OP_FUNCTION_PROTO(CLI); // CLI
- ZEROBYTE_OP_FUNCTION_PROTO(CLV); // CLV
- ONEBYTE_OP_FUNCTION_PROTO(CMP); // CMP
- ONEBYTE_OP_FUNCTION_PROTO(CPX); // CPX
- ONEBYTE_OP_FUNCTION_PROTO(CPY); // CPY
- TWOBYTE_OP_FUNCTION_PROTO(DEC); // DEC
- ZEROBYTE_OP_FUNCTION_PROTO(DEX); // DEX
- ZEROBYTE_OP_FUNCTION_PROTO(DEY); // DEY
- ONEBYTE_OP_FUNCTION_PROTO(EOR); // EOR
- TWOBYTE_OP_FUNCTION_PROTO(INC); // INC
- ZEROBYTE_OP_FUNCTION_PROTO(INX); // INX
- ZEROBYTE_OP_FUNCTION_PROTO(INY); // INY
- TWOBYTE_OP_FUNCTION_PROTOPC(JMP); // JMP
- TWOBYTE_OP_FUNCTION_PROTOPC(JSR); // JSR
- ONEBYTE_OP_FUNCTION_PROTO(LDA); // LDA
- ONEBYTE_OP_FUNCTION_PROTO(LDX); // LDX
- ONEBYTE_OP_FUNCTION_PROTO(LDY); // LDY
- TWOBYTE_OP_FUNCTION_PROTO(LSR); // LSR
- ZEROBYTE_OP_FUNCTION_PROTO(NOP); // NOP
- ONEBYTE_OP_FUNCTION_PROTO(ORA); // ORA
- ZEROBYTE_OP_FUNCTION_PROTO(PHA); // PHA
- ZEROBYTE_OP_FUNCTION_PROTO(PHP); // PHP
- ZEROBYTE_OP_FUNCTION_PROTO(PLA); // PLA
- ZEROBYTE_OP_FUNCTION_PROTO(PLP); // PLP
- TWOBYTE_OP_FUNCTION_PROTO(ROL); // ROL
- TWOBYTE_OP_FUNCTION_PROTO(ROR); // ROR
- ZEROBYTE_OP_FUNCTION_PROTO(RTI); // RTI
- ZEROBYTE_OP_FUNCTION_PROTO(RTS); // RTS
- ONEBYTE_OP_FUNCTION_PROTO(SBC); // SBC
- ZEROBYTE_OP_FUNCTION_PROTO(SEC); // SEC
- ZEROBYTE_OP_FUNCTION_PROTO(SED); // SED
- ZEROBYTE_OP_FUNCTION_PROTO(SEI); // SEI
- TWOBYTE_OP_FUNCTION_PROTO(STA); // STA
- TWOBYTE_OP_FUNCTION_PROTO(STX); // STX
- TWOBYTE_OP_FUNCTION_PROTO(STY); // STY
- ZEROBYTE_OP_FUNCTION_PROTO(TAX); // TAX
- ZEROBYTE_OP_FUNCTION_PROTO(TAY); // TAY
- ZEROBYTE_OP_FUNCTION_PROTO(TSX); // TSX
- ZEROBYTE_OP_FUNCTION_PROTO(TXA); // TXA
- ZEROBYTE_OP_FUNCTION_PROTO(TXS); // TXS
- ZEROBYTE_OP_FUNCTION_PROTO(TYA); // TYA
-
- #define OPCODEMODE(op, mode) op##_##mode = ##op+##mode
- #define OPCODEMODEEXCEPTION(op, mode, val) op##_##mode = ##val
-
- // Create enums for command values
- enum {
- OPCODEMODE(ADC, Immediate),
- OPCODEMODE(ADC, Absolute),
- OPCODEMODE(ADC, ZeroPage),
- OPCODEMODE(ADC, IndX),
- OPCODEMODE(ADC, IndY),
- OPCODEMODE(ADC, ZeroPageX),
- OPCODEMODE(ADC, AbsoluteX),
- OPCODEMODE(ADC, AbsoluteY),
- OPCODEMODE(AND, Immediate),
- OPCODEMODE(AND, Absolute),
- OPCODEMODE(AND, ZeroPage),
- OPCODEMODE(AND, IndX),
- OPCODEMODE(AND, IndY),
- OPCODEMODE(AND, ZeroPageX),
- OPCODEMODE(AND, AbsoluteX),
- OPCODEMODE(AND, AbsoluteY),
- OPCODEMODE(ASL, Absolute),
- OPCODEMODE(ASL, ZeroPage),
- OPCODEMODE(ASL, Accumulator),
- OPCODEMODE(ASL, ZeroPageX),
- OPCODEMODE(ASL, AbsoluteX),
- OPCODEMODE(BCC, Relative),
- OPCODEMODE(BCS, Relative),
- OPCODEMODE(BEQ, Relative),
- OPCODEMODE(BNE, Relative),
- OPCODEMODE(BMI, Relative),
- OPCODEMODE(BPL, Relative),
- OPCODEMODE(BVC, Relative),
- OPCODEMODE(BVS, Relative),
- OPCODEMODE(BIT, Absolute),
- OPCODEMODE(BIT, ZeroPage),
- OPCODEMODE(BRK, None),
- OPCODEMODE(CLC, None),
- OPCODEMODE(CLD, None),
- OPCODEMODE(CLI, None),
- OPCODEMODE(CLV, None),
- OPCODEMODE(CMP, Immediate),
- OPCODEMODE(CMP, Absolute),
- OPCODEMODE(CMP, ZeroPage),
- OPCODEMODE(CMP, IndX),
- OPCODEMODE(CMP, IndY),
- OPCODEMODE(CMP, ZeroPageX),
- OPCODEMODE(CMP, AbsoluteX),
- OPCODEMODE(CMP, AbsoluteY),
- OPCODEMODE(CPX, Immediate),
- OPCODEMODE(CPX, Absolute),
- OPCODEMODE(CPX, ZeroPage),
- OPCODEMODE(CPY, Immediate),
- OPCODEMODE(CPY, Absolute),
- OPCODEMODE(CPY, ZeroPage),
- OPCODEMODE(DEC, Absolute),
- OPCODEMODE(DEC, ZeroPage),
- OPCODEMODE(DEC, ZeroPageX),
- OPCODEMODE(DEC, AbsoluteX),
- OPCODEMODE(DEX, None),
- OPCODEMODE(DEY, None),
- OPCODEMODE(EOR, Immediate),
- OPCODEMODE(EOR, Absolute),
- OPCODEMODE(EOR, ZeroPage),
- OPCODEMODE(EOR, IndX),
- OPCODEMODE(EOR, IndY),
- OPCODEMODE(EOR, ZeroPageX),
- OPCODEMODE(EOR, AbsoluteX),
- OPCODEMODE(EOR, AbsoluteY),
- OPCODEMODE(INC, Absolute),
- OPCODEMODE(INC, ZeroPage),
- OPCODEMODE(INC, ZeroPageX),
- OPCODEMODE(INC, AbsoluteX),
- OPCODEMODE(INX, None),
- OPCODEMODE(INY, None),
- OPCODEMODE(JMP, Absolute),
- OPCODEMODE(JMP, Indirect),
- OPCODEMODE(JSR, Absolute),
- OPCODEMODE(LDA, Immediate),
- OPCODEMODE(LDA, Absolute),
- OPCODEMODE(LDA, ZeroPage),
- OPCODEMODE(LDA, IndX),
- OPCODEMODE(LDA, IndY),
- OPCODEMODE(LDA, ZeroPageX),
- OPCODEMODE(LDA, AbsoluteX),
- OPCODEMODE(LDA, AbsoluteY),
- OPCODEMODEEXCEPTION(LDX, Immediate, _LDX_Immediate),
- OPCODEMODE(LDX, Absolute),
- OPCODEMODE(LDX, ZeroPage),
- OPCODEMODE(LDX, AbsoluteY),
- OPCODEMODE(LDX, ZeroPageY),
- OPCODEMODEEXCEPTION(LDY, Immediate, _LDY_Immediate),
- OPCODEMODE(LDY, Absolute),
- OPCODEMODE(LDY, ZeroPage),
- OPCODEMODE(LDY, ZeroPageX),
- OPCODEMODE(LDY, AbsoluteX),
- OPCODEMODE(LSR, Absolute),
- OPCODEMODE(LSR, ZeroPage),
- OPCODEMODE(LSR, Accumulator),
- OPCODEMODE(LSR, ZeroPageX),
- OPCODEMODE(LSR, AbsoluteX),
- OPCODEMODE(NOP, None),
- OPCODEMODE(ORA, Immediate),
- OPCODEMODE(ORA, Absolute),
- OPCODEMODE(ORA, ZeroPage),
- OPCODEMODE(ORA, IndX),
- OPCODEMODE(ORA, IndY),
- OPCODEMODE(ORA, ZeroPageX),
- OPCODEMODE(ORA, AbsoluteX),
- OPCODEMODE(ORA, AbsoluteY),
- OPCODEMODE(PHA, None),
- OPCODEMODE(PHP, None),
- OPCODEMODE(PLA, None),
- OPCODEMODE(PLP, None),
- OPCODEMODE(ROL, Absolute),
- OPCODEMODE(ROL, ZeroPage),
- OPCODEMODE(ROL, Accumulator),
- OPCODEMODE(ROL, ZeroPageX),
- OPCODEMODE(ROL, AbsoluteX),
- OPCODEMODE(ROR, Absolute),
- OPCODEMODE(ROR, ZeroPage),
- OPCODEMODE(ROR, Accumulator),
- OPCODEMODE(ROR, ZeroPageX),
- OPCODEMODE(ROR, AbsoluteX),
- OPCODEMODE(RTI, None),
- OPCODEMODE(RTS, None),
- OPCODEMODE(SBC, Immediate),
- OPCODEMODE(SBC, Absolute),
- OPCODEMODE(SBC, ZeroPage),
- OPCODEMODE(SBC, IndX),
- OPCODEMODE(SBC, IndY),
- OPCODEMODE(SBC, ZeroPageX),
- OPCODEMODE(SBC, AbsoluteX),
- OPCODEMODE(SBC, AbsoluteY),
- OPCODEMODE(SEC, None),
- OPCODEMODE(SED, None),
- OPCODEMODE(SEI, None),
- OPCODEMODE(STA, Absolute),
- OPCODEMODE(STA, ZeroPage),
- OPCODEMODE(STA, IndX),
- OPCODEMODE(STA, IndY),
- OPCODEMODE(STA, ZeroPageX),
- OPCODEMODE(STA, AbsoluteX),
- OPCODEMODE(STA, AbsoluteY),
- OPCODEMODE(STX, Absolute),
- OPCODEMODE(STX, ZeroPage),
- OPCODEMODE(STX, ZeroPageY),
- OPCODEMODE(STY, Absolute),
- OPCODEMODE(STY, ZeroPage),
- OPCODEMODE(STY, ZeroPageX),
- OPCODEMODE(TAX, None),
- OPCODEMODE(TAY, None),
- OPCODEMODE(TSX, None),
- OPCODEMODE(TXA, None),
- OPCODEMODE(TXS, None),
- OPCODEMODE(TYA, None)
- };
-